/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller;

import com.thienloc.omap.entity.TrafficReport;
import com.thienloc.omap.session.RequestQueueFacade;
import com.thienloc.omap.session.RequestQueueHistFacade;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class TrafficReportBean implements Serializable {
    
    @EJB
    private RequestQueueHistFacade requestQueueHistFacade;
    @EJB
    private RequestQueueFacade requestQueueFacade;
    private List<TrafficReport> trafficReports = new ArrayList<TrafficReport>();
    private Date startTime;
    private Date endTime;
    private String cpNumber;
    private String service;
    
    @PostConstruct
    public void init() {
        startTime = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        endTime = calendar.getTime();
    }
    
    public void viewReport() {
        try {
            this.trafficReports = requestQueueHistFacade.getTrafficReport(startTime, endTime, service, cpNumber);
            trafficReports.addAll(requestQueueFacade.getTrafficReport(startTime, endTime, service, cpNumber));
        } catch (Exception ex) {
            LoggerFactory.getLogger(TrafficReportBean.class.getName()).error("", ex);
        }
    }
    
    public Date getEndTime() {
        return endTime;
    }
    
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    
    public List<TrafficReport> getTrafficReports() {
        return trafficReports;
    }
    
    public void setTrafficReports(List<TrafficReport> trafficReports) {
        this.trafficReports = trafficReports;
    }
    
    public Date getStartTime() {
        return startTime;
    }
    
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
    
    public String getCpNumber() {
        return cpNumber;
    }
    
    public void setCpNumber(String cpNumber) {
        this.cpNumber = cpNumber;
    }
    
    public String getService() {
        return service;
    }
    
    public void setService(String service) {
        this.service = service;
    }
}
